package gold.digger;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC896 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean isMonotonic(int[] arr) {
            if (null == arr || arr.length <= 2) return true;

            int start = 0;
            while (start < arr.length - 1 && arr[start] == arr[start + 1]) ++start;
            if (start == arr.length - 1) return true;

            if (arr[start] < arr[start + 1]) {
                for (int i = start; i < arr.length - 1; i++) {
                    if (arr[i] > arr[i + 1]) return false;
                }
                return true;
            } else {
                for (int i = start; i < arr.length - 1; i++) {
                    if (arr[i] < arr[i + 1]) return false;
                }
                return true;
            }

        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[1,1,1,2,3]");
        System.out.println(solution.isMonotonic(arr));
    }

    public static void main(String[] args) throws Exception {
        LC896 an = new LC896();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
